package com.onnoa.jenkins.test.controller;

import cn.hutool.core.lang.UUID;

import com.onnoa.jenkins.test.common.cache.RedisTestCache;
import com.onnoa.jenkins.test.result.ResultBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/redis")
public class RedisTestController {

    private static Logger logger = LoggerFactory.getLogger(RedisTestController.class);

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping(value = "/test/{times}")
    public ResultBean redisTest(@PathVariable("times") Integer times){
        long start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
            RedisTestCache.REDIS_TEST_CACHE.set(UUID.fastUUID().toString(), UUID.fastUUID().toString());
        }
        long end = System.currentTimeMillis();
        logger.info("redis String 类型设值花费时间：{} ms", end - start);

        String hKey = "shop:redis:test:";
        long hStart = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
            redisTemplate.opsForHash().put(hKey, UUID.fastUUID().toString(),UUID.fastUUID().toString());
        }
        long hEnd = System.currentTimeMillis();
        logger.info("redis Hash 类型设值花费时间：{} ms", hEnd - hStart);


        return ResultBean.success();
    }



}

